#include "gnurilla.h"

GtkActionGroup *gnurilla_menubar_action_group (GnurillaData *gd)
{
	GtkActionGroup *menubar_action_group;
	
	static GtkActionEntry menubar_entries[] = {
		{"FileMenu", NULL, "_File" },
		{"New", GTK_STOCK_NEW, "_Nuovo...", "<control>N", "Crea un nuovo file", G_CALLBACK(gnurilla_add_notebook_page) },
		{"Open", GTK_STOCK_OPEN, "_Apri...", "<control>O", "Apri un file", NULL },
		{"Save", GTK_STOCK_SAVE, "_Salva", "<control>S", "Salva file modificato", NULL },
		{"SaveAs", GTK_STOCK_SAVE_AS, "Salva Come...", "<control><shift>S", "Salva un file", NULL },
		{"Quit", GTK_STOCK_QUIT, "_Esci", "<control>Q", "Esci", G_CALLBACK(gnurilla_cb_delete_event) },
		{"CloseTab", GTK_STOCK_CLOSE, "Chiudi", "<control>W", "Chiudi", NULL },
		{"Preferences", GTK_STOCK_PREFERENCES, "_Preferenze...", "<alt>P", "Preferenze", NULL },
			
		{"EditMenu", NULL, "_Modifica" },
		{"Cut", GTK_STOCK_CUT, "Taglia", "<control>X", "Taglia", NULL },
		{"Copy", GTK_STOCK_COPY, "Copia", "<control>C", "Copia", NULL },
		{"Paste", GTK_STOCK_PASTE, "Incolla", "<control>V", "Incolla", NULL },
		{"SelectAll", GTK_STOCK_SELECT_ALL, "Seleziona Tutto", "<control>A", "Seleziona tutto il testo scritto", NULL },
		{"DeselectAll", NULL, "Deseleziona Tutto", NULL, NULL, NULL },
		{"RemoveAll", NULL, "Rimuovi Tutto", NULL, "Rimuove tutto il testo scritto", NULL },
		{"UnDo", GTK_STOCK_UNDO, "Annulla", "<control>Z", "Annulla azione", NULL },
		{"ReDo", GTK_STOCK_REDO, "Ripeti", "<control>Y", "Ripeti azione", NULL },
		{"Find", GTK_STOCK_FIND, "Trova e Rimpiazza...", "<control>F", "Trova una parola all\'interno del testo", NULL },
		
		{"GoMenu", NULL, "_Vai" },
		{"PrevTab", GTK_STOCK_GO_BACK, "Precedente", "<shift>F6", "Precedente", NULL },
		{"NextTab", GTK_STOCK_GO_FORWARD, "Successivo", "F6", "Successivo", NULL },
		
		{"HelpMenu", NULL, "_Aiuto" },
		{"About", GTK_STOCK_ABOUT, "_Informazioni...", "<control>I", "Informazioni su Gnurilla", gnurilla_about },
	};
	
	static guint n_entries = G_N_ELEMENTS (menubar_entries);
	
	menubar_action_group = gtk_action_group_new ("AppWindowActions");
      	gtk_action_group_add_actions (menubar_action_group, menubar_entries, n_entries, gd);
	return menubar_action_group;
};

GtkWidget *gnurilla_create_menubar (GnurillaData *gd, char *filename)
{
	GtkWidget *window;
	GtkWidget *menubar;
	GtkUIManager *merge;
	GtkActionGroup *menubar_action_group;
	GError *error = NULL;
	
	window = gd->window;
	menubar_action_group = gnurilla_menubar_action_group(gd);
	
	merge = gtk_ui_manager_new();
	gtk_ui_manager_insert_action_group(merge, menubar_action_group, 0);
	gtk_ui_manager_add_ui_from_file(merge, filename, &error);
	gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group (merge));
	
	menubar = gtk_ui_manager_get_widget(merge, "/Menubar");
	
	return menubar;
};
